home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / hiarcmen / loadme.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  7.0 KB  |  179 lines  |  [TEXT/ttxt]

  1. --<<<-
  2. --*******************************************************************************
  3. --*          Demo for:    MenuButton
  4. --*    Required files: textmenu.sx
  5. --*            Author:    Su Quek - Kaleida Labs, Inc.
  6. --*-----------------------------------------------------------------------------*
  7. --*       Description: This script demonstrates how to create a hierarchical text
  8. --*                    menu.
  9. --*                    When you run "hiarcmen.sxt", you should see a window
  10. --*                    with a settings menu with the following menu structure:
  11. --*
  12. --*                        Settings - Reset
  13. --*                                 - Color - Fill   - Red
  14. --*                                                  - Green
  15. --*                                                  - Blue
  16. --*                                         - Stroke - Red
  17. --*                                                  - Green
  18. --*                                                  - Blue
  19. --*
  20. --*******************************************************************************
  21.  
  22. module TextMenuModule
  23.     uses ScriptX
  24. end
  25.  
  26. in module TextMenuModule
  27.  
  28. --*=============================================================================*
  29. --* Load required files
  30. --*=============================================================================*
  31. -- Load MenuButton
  32. fileIn theScriptDir name:"textmenu.sx"
  33.  
  34.  
  35. --*=============================================================================*
  36. --*    Define Demo 
  37. --*=============================================================================*
  38. class Demo (Window)
  39. end
  40.  
  41. --*=============================================================================*
  42. --*       Method name:    makeMenu
  43. --*             Class:    Demo
  44. --*             Usage: makeMenu self 
  45. --*-----------------------------------------------------------------------------*
  46. --*       Description: Makes the menu and its submenus.
  47. --*=============================================================================*
  48. method makeMenu self {class Demo} ->
  49. (
  50.     --*=========================================================================*
  51.     --* Create the settings menu
  52.     --* Note: the 'supermenu' keyword is 'undefined'
  53.     --*=========================================================================*
  54.     local settingsMenu := new MenuButton supermenu:undefined \
  55.                                          label:"Settings" \
  56.                                          width:60
  57.     
  58.     --*=========================================================================*
  59.     --* Create the reset item under the settings menu
  60.     --*=========================================================================*
  61.     addmenuitem settingsMenu "Reset" self (authordata me -> \
  62.             authordata.fill := authordata.stroke := blackBrush)
  63.  
  64.     --*=========================================================================*
  65.     --* Create the color sub-menu
  66.     --* Note: the 'supermenu' keyword is set to the menubutton that invokes it
  67.     --*          i.e. settingsMenu
  68.     --*=========================================================================*
  69.     local colorMenu := new MenuButton supermenu:settingsMenu \
  70.                                       label:"Color" \
  71.                                       placement:@menuRight
  72.     
  73.     --*=========================================================================*
  74.     --* Create the fill sub-sub-menu
  75.     --* Note: the 'supermenu' keyword is set to the menubutton that invokes it
  76.     --*          i.e. colorMenu
  77.     --*=========================================================================*
  78.     local fillMenu := new MenuButton supermenu:colorMenu \
  79.                                      label:"Fill" \
  80.                                      placement:@menuRight
  81.  
  82.     --*=========================================================================*
  83.     --* Create the red, green and blue items under the fill menu
  84.     --*=========================================================================*
  85.     addmenuitem fillMenu "Red" self (authordata me ->  \
  86.             authordata.fill := (new Brush color:redColor))
  87.     addmenuitem fillMenu "Green" self (authordata me -> \
  88.             authordata.fill := (new Brush color:greenColor))
  89.     addmenuitem fillMenu "Blue" self (authordata me -> \
  90.             authordata.fill := (new Brush color:blueColor))
  91.     
  92.     --*=========================================================================*
  93.     --* Create the stroke sub-sub-menu
  94.     --* Note: the 'supermenu' keyword is set to the menubutton that invokes it
  95.     --*          i.e. colorMenu
  96.     --*=========================================================================*
  97.     local strokeMenu := new MenuButton supermenu:colorMenu \
  98.                                        label:"Stroke" \
  99.                                        placement:@menuRight
  100.  
  101.     --*=========================================================================*
  102.     --* Create the red, green and blue items under the fill menu
  103.     --*=========================================================================*
  104.     addmenuitem strokeMenu "Red" self (authordata me ->  \
  105.             authordata.stroke := (new Brush color:redColor))
  106.     addmenuitem strokeMenu "Green" self (authordata me -> \
  107.             authordata.stroke := (new Brush color:greenColor))
  108.     addmenuitem strokeMenu "Blue" self (authordata me -> \
  109.             authordata.stroke := (new Brush color:blueColor))
  110.  
  111.     return settingsMenu
  112. )
  113.  
  114. --*=============================================================================*
  115. --*       Method name:    init
  116. --*             Class:    Demo
  117. --*             Usage: init self 
  118. --*-----------------------------------------------------------------------------*
  119. --*       Description: Creates a 200x200 window.
  120. --*=============================================================================*
  121. method init self {class Demo} #rest args ->
  122. (
  123.     -- Create a 200x200 window 
  124.     apply nextMethod self boundary:(new Rect x2:200 y2:200) \
  125.                           centered:true \
  126.                           fill:blackBrush \
  127.                           stroke:blackBrush \
  128.                           name:"Select from Menu" args
  129.     return self
  130. )
  131.  
  132. --*=============================================================================*
  133. --*       Method name:    afterInit
  134. --*             Class:    Demo
  135. --*             Usage: afterInit self 
  136. --*-----------------------------------------------------------------------------*
  137. --*       Description: Makes the menu and appends it to the demo window.
  138. --*=============================================================================*
  139. method afterInit self {class Demo} #rest args ->
  140. (        
  141.     --*=========================================================================*
  142.     --* Create an actuator controller to control all the buttons in the demo
  143.     --*    window.
  144.     --*=========================================================================*
  145.     new ActuatorController space:self wholespace:true
  146.     
  147.     --*=========================================================================*
  148.     --* Add menu to the demo window and display it
  149.     --*=========================================================================*
  150.     prepend self (makeMenu self)
  151.     show self
  152.     
  153.     return self
  154. )
  155.  
  156. --*=============================================================================*
  157. --*    Create a title container
  158. --*=============================================================================*
  159. object tc (TitleContainer)
  160.     dir        : theScriptDir
  161.     path    : "textmenu.sxt" 
  162.     name    : "Hierarchical Text Menu"
  163. end        
  164.         
  165. --*=============================================================================*
  166. --*    Create demo
  167. --*=============================================================================*
  168. object win (Demo)
  169.     title:tc
  170. end
  171.  
  172. --*=============================================================================*
  173. --*    Store module in the title container
  174. --*=============================================================================*
  175. append tc (getModule @TextMenuModule)
  176. tc.startUpAction := (tc -> load tc[1]
  177.                            show win)
  178. close tc
  179. -->>>